package com.tianruan.dc.modules.sys.user.api;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tianruan.dc.common.utils.StringUtils;
import com.tianruan.dc.modules.sys.user.entity.db.MajorDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import com.tianruan.dc.modules.sys.user.entity.db.GradeDO;
import com.tianruan.dc.modules.sys.user.entity.dto.GradeDTO;
import com.tianruan.dc.modules.sys.user.service.IGradeService;
import com.tianruan.dc.common.utils.PageUtils;
import com.tianruan.dc.common.utils.response.VResponse;



@RestController
@RequestMapping("/api/sys/user/grade")
public class GradeController {

    @Autowired
    private IGradeService gradeService;

    @PreAuthorize("hasAnyAuthority('admin', 'officeAdmin')")
    @GetMapping
    public VResponse<List<GradeDO>> list(@RequestParam(value = "officeId", required = false) String officeId,
                                         @RequestParam(value = "majorId", required = false) String majorId) {
        return VResponse.success(gradeService.queryList(officeId, majorId));
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public VResponse info(@PathVariable("id") String id){
		GradeDO grade = gradeService.getById(id);

        return VResponse.success("grade", grade);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public VResponse save(@RequestBody GradeDO grade){
		gradeService.save(grade);

        return VResponse.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public VResponse update(@RequestBody GradeDO grade){
		gradeService.updateById(grade);

        return VResponse.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public VResponse delete(@RequestBody String[] ids){
		gradeService.removeByIds(Arrays.asList(ids));

        return VResponse.success();
    }

}
